$(function(){
	
	document.documentElement.style.fontSize = window.innerWidth/3.75 + 'px';

	var giftId = $("#gift").val();
	var userId = $("#userId").val();
	var inviteNum = $("#inviteNum").val();
	var status = $("#status").val();
	
	var shareUrl = "";
	var shareTitle = "";
	
	//分享过
	if(status == '3') {
		if(giftId == '1') {
			$('#optionsRadios1').prop("checked",'checked');
		}
		if(giftId == '2') {
			$('#optionsRadios2').prop("checked",'checked');
		}
		$('.radio input').attr({
			'disabled': true
		});
		$('.share-btn').on('click', function() {
			startShare(userId, giftId);
		});
	}
	//没分享过
	else {
		$('.radio input').attr({
			'disabled': false
		});
		$('.share-btn').on('click', function() {
			giftId = $('.radio input:checked').attr('value');
			startShare(userId, giftId);
		});
	}

	//发起分享
	function startShare(userId, giftId) {
		$.ajax({
			type: "post",
			url: "/dingding-web/moonActivityAction!startShare.action",
			dataType: "jsonp",
			async: false,
			jsonp: "callback",
			jsonpCallback: "success_jsop",
			data: {
				userId: userId,
				giftId: giftId
			},
			success: function(data) {
				shareUrl = data.responseBody.activityUrl;
				shareTitle = data.responseBody.activityTitle;
				
				//初始化微信
				initWechat();
			}
		});
	}
	
	
	function initWechat(){
		
		var timestampVal = $("#timestamp").val();
		var nonceStrVal = $("#nonceStr").val();
		var signatureVal = $("#signature").val();
		var appId = $("#appId").val();
		
		wx.config({
		    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
		    appId: appId, // 必填，公众号的唯一标识
		    timestamp: timestampVal, // 必填，生成签名的时间戳
		    nonceStr: nonceStrVal, // 必填，生成签名的随机串
		    signature: signatureVal,// 必填，签名，见附录1
		    jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage']
		});
		
		wx.ready(function(){
			
			/////////////改为正式
			var baseUrl = 'http://www.pdhz-dddc.cn';
			
			shareUrl = baseUrl + shareUrl;

			wx.onMenuShareTimeline({
			    title: '中秋活动', // 分享标题
			    desc: shareTitle,
			    link: shareUrl, // 分享链接
			    imgUrl: "http://ddride-server-image.oss-cn-shanghai.aliyuncs.com/share.png", // 分享图标
			    success: function () { 
			    },
			    cancel: function () { 
			    }
			});
			
			wx.onMenuShareAppMessage({
			    title: '中秋活动',
			    desc: shareTitle,
			    link: shareUrl,
			    imgUrl: "http://ddride-server-image.oss-cn-shanghai.aliyuncs.com/share.png", // 分享图标
			    success: function () {
			    },
			    cancel: function () { 
			    }
			});
		});
		
		
	}
	
	
})
